/*
 *  Copyright (c) 2022 ZhuHai Jieli Technology Co.,Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef ARCH_SDMMC_H
#define ARCH_SDMMC_H

#include "device/sdmmc.h"

struct sdmmc_platform_data {
    char port;
    u8 irq;
    u8 data_width;
    u8 priority;
    u8 detect_mode;
    u8 detect_io;
    u8 detect_io_level;
    u8 detect_time_interval;
    u32 detect_timeout;
    u32 speed;
    volatile u16 *sfr;
    int (*detect_func)(const struct sdmmc_platform_data *);
    void (*port_init)(const struct sdmmc_platform_data *, int mode);
    void (*power)(int on);
};

#define SD0_PLATFORM_DATA_BEGIN(data) \
    static const struct sdmmc_platform_data data = {

#define SD0_PLATFORM_DATA_END() \
    .irq                     = IRQ_SD0_IDX, \
    .sfr                    = (volatile u16 *)JL_SD0, \
    .port_init                 = sdmmc_0_port_init, \
    .detect_time_interval     = 250, \
    .detect_timeout         = 1000, \
};

extern const struct device_operations sd0_dev_ops;

extern void sdmmc_0_port_init(const struct sdmmc_platform_data *, int mode);
extern int sdmmc_0_clk_detect(const struct sdmmc_platform_data *);
extern int sdmmc_0_io_detect(const struct sdmmc_platform_data *);

extern int sdmmc_cmd_detect(const struct sdmmc_platform_data *);

extern void sd_set_power(u8 enable);

#define SD1_PLATFORM_DATA_BEGIN(data) \
    static const struct sdmmc_platform_data data = {

#define SD1_PLATFORM_DATA_END() \
    .irq                     = IRQ_SD1_IDX, \
    .sfr                    = (volatile u16 *)JL_SD1, \
    .port_init                 = sdmmc_1_port_init, \
    .detect_time_interval     = 250, \
    .detect_timeout         = 1000, \
};

extern const struct device_operations sd_dev_ops;

extern void sdmmc_1_port_init(const struct sdmmc_platform_data *, int mode);
extern int sdmmc_1_clk_detect(const struct sdmmc_platform_data *);
extern int sdmmc_1_io_detect(const struct sdmmc_platform_data *);

extern void sdmmc_2_port_init(const struct sdmmc_platform_data *, int mode);
extern int sdmmc_2_clk_detect(const struct sdmmc_platform_data *);

extern u8 sd_io_suspend(u8 sdx, u8 sd_io);
extern u8 sd_io_resume(u8 sdx, u8 sd_io);

#endif
